package com.juttec.freshbird.pet;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class ZixunContentActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(R.layout.activity_zixun_content);
        initViews();
    }

    private void initViews() {
        ImageButton ibShoucang = (ImageButton) findViewById(R.id.ib_shoucang);
        ImageButton ibZhuanfa = (ImageButton) findViewById(R.id.ib_zhuanfa);
        ImageButton ibFanhui = (ImageButton) findViewById(R.id.ib_fanhui);
        TextView etneirongxiepinglun = (TextView) findViewById(R.id.et_neirong_xiepinglun);
        TextView tvNeirongShumu = (TextView) findViewById(R.id.tv_neirong_shumu);
        ibFanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ZixunContentActivity.this.finish();
            }
        });
        ibZhuanfa.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ZixunContentActivity.this, "已转发", Toast.LENGTH_SHORT).show();
            }
        });
        ibShoucang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(ZixunContentActivity.this, "已收藏", Toast.LENGTH_SHORT).show();
            }
        });
        tvNeirongShumu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ZixunContentActivity.this, ZixunDiscussActivity.class));
            }
        });
        etneirongxiepinglun.setOnClickListener(new View.OnClickListener() {

            private EditText et;

            @Override
            public void onClick(View v) {
                Dialog dialog = new Dialog(ZixunContentActivity.this);
                View inflate = View.inflate(ZixunContentActivity.this, R.layout.dialog, null);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(inflate);
                et = (EditText) inflate.findViewById(R.id.et_dialog);
                //设置可获得焦点
                et.setFocusable(true);
                //请求获得焦点
                et.requestFocus();
                dialog.setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialog) {
                        //调用系统输入法
                        InputMethodManager inputManager = (InputMethodManager) et
                                .getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                        inputManager.showSoftInput(et, 0);
                    }
                });

                Window dialogWindow = dialog.getWindow();
                dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
                WindowManager.LayoutParams lp = dialogWindow.getAttributes();// 获取对话框当前的参数值
                WindowManager m = getWindowManager();
                Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
                lp.height = (int) (d.getHeight() * 0.5); // 高度设置为屏幕的0.6
                lp.width = (int) (d.getWidth()); // 宽度设置为屏幕宽度
                dialogWindow.setAttributes(lp);
                dialogWindow.setGravity(Gravity.BOTTOM);
                dialog.show();
            }

        });
    }
}
